var {
  randomUtils,
  clickUtils,
  swipeUtils,
  timeUtils,
  logUtils,
} = require("../../utils/index");
var { Action } = require("../../base/index");
var pointMap = require("./pointMap");
var aRead = new Action("阅读", {});
aRead.exec = function () {
  if (randomUtils.possible(10, 30)) {
    this.read();
  } else {
    clickUtils.clickPointMap(pointMap.首页.视频);
    sleep(randomUtils.getRandom(3, 5, 1000));
    this.watch();
  }
};
aRead.read = function () {
  var baseSpan = 30;
  var span = randomUtils.getRandom(baseSpan, baseSpan + 30);
  logUtils.info("将read：", span, "秒");
  var startTime = Date.now();
  while (true) {
    sleep(randomUtils.getRandom(3, 5, 1000));
    swipeUtils.swipeUp();
    var hasExec = timeUtils.hasExec(startTime);
    logUtils.info("hasExec:", hasExec, "/", span);
    if (hasExec > span) {
      logUtils.info("结束本轮read");
      break;
    }
  }
};
aRead.watch = function () {
  var baseSpan = 30;
  var span = randomUtils.getRandom(baseSpan, baseSpan + 30);
  logUtils.info("将watch：", span, "秒");
  var startTime = Date.now();
  while (true) {
    sleep(randomUtils.getRandom(10, 35, 1000));
    swipeUtils.swipeVideo();
    var hasExec = timeUtils.hasExec(startTime);
    logUtils.info("hasExec:", hasExec, "/", span);
    if (hasExec > span) {
      logUtils.info("结束本轮watch");
      break;
    }
  }
};
module.exports = aRead;
